package com.example.leetdemo.plan1;

import java.util.ArrayDeque;
import java.util.Queue;

public class Sword041 {


    public static void main(String[] args) {
        MovingAverage movingAverage = new MovingAverage(10);
    }
    public static class MovingAverage {
        Queue<Integer> queue;
        double sum;
        int size;
        /** Initialize your data structure here. */
        public MovingAverage(int size) {
            queue = new ArrayDeque<>();
            sum = 0;
            this.size = size;
        }

        public double next(int val) {
            queue.add(val);
            sum += val;
            if (queue.size() > size) {
                sum -= queue.remove();
            }
            return sum / queue.size();
        }
    }
}
